<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AbstractModule
 *
 * @author ngh
 */
abstract class ModuleController extends Controller {    
    
    public $path_to_module;
    function onCreatePage() {}
    final public function __construct(RequestContext $context) {
        parent::__construct($context);
        
        $parts = explode('\\',$this->getDir());
        
        $parent_folder = $parts[count($parts)-3];
        $module_folder = $parts[count($parts)-2];

        $this->path_to_module = $parent_folder.'/'.$module_folder;

    }

    protected function getDir() {
        $reflector = new ReflectionClass(get_class($this));
        return dirname($reflector->getFileName());
    }
    
    protected function requireLibFile($filename) {
        require_once DIR_MODULES.$this->path_to_module.'/lib/'.$filename;
    }


    public function getAllowedBlocks($checked_method) {
        $method = new ReflectionMethod($this, $checked_method);
        $components = getDocComment($method->getDocComment(), '@blocks');
        if(empty($components)) return array();
        $allowed_components = explode(',', $components);
        array_walk($allowed_components, function ($item, $key) use (&$allowed_components) {
                    $allowed_components[$key] = trim($item);
                });

        return $allowed_components;
    }
//    /**
//     * проверяет доступен ли путь
//     * @param type $path
//     * @return type
//     */
//    public function isAllowedPath($path, $checked_method)
//    {
//        $method = new ReflectionMethod($this, $checked_method);
//        $allowed_paths = explode(',', getDocComment($method->getDocComment(), '@paths'));
//        array_walk($allowed_paths, function ($item, $key) use (&$allowed_paths){$allowed_paths[$key] = trim($item);});
//        //dump($allowed_paths, 'allowed paths');   
//        return in_array($path, $allowed_paths);
//    }
    
    protected function dump($param) {
        echo"<pre>";
        var_dump($param);
        echo"</pre>";
    }
//    
//    public function __call($name, $arguments) {
//
//        if(preg_match('/^handler_([a-z_A-Z]+)$/', $name, $matches))
//        {
//            //invokeAll($hook_name, $args = array(), &$return  = null)
//                    //$this->hook->invokeAll('validate', $arguments, $arguments);
//                    call_user_func_array('validate_'.$matches[1], $this, $arguments);
//                    //$this->hook->invokeAll('submit', $arguments, $arguments);
//                    call_user_func_array('submit_'.$matches[1], $this, $arguments);
//
//        }
//    }
    
    
    
    
}

?>
